<?php

/**
 * @copyright   FOSP
 * @version     20120411
 * @todo        Format data rating_player_statistic
 * @name        Fpt_Business_RatingPlayerStatistic_Metadata_RatingPlayerStatistic
 * @author      QuangTM 
 */
class Fpt_Business_RatingPlayerStatistic_Metadata_RatingPlayerStatistic
{
    
    /**
     *
     * @var int
     */
    private $_matchID;
    
    /**
     *
     * @var int
     */
    private $_teamID;
    
    /**
     *
     * @var int
     */
    private $_playerID;
    
    /**
     *
     * @var string
     */
    private $_playerImage;


    /**
     *
     * @var int
     */
    private $_totalUserID;
    
    /**
     *
     * @var int
     */
    private $_ratingUser;
    
    /**
     *
     * @var int
     */
    private $_ratingVne;
    
    /**
     *
     * @var double
     */
    private $_avgRating;
    
    /**
     *
     * @var double
     */
    private $_avgUser;

    public function __construct()
    {
        $this->_matchID = 0;
        $this->_playerID = 0;
        $this->_playerImage = '';
        $this->_ratingUser = 0;
        $this->_ratingVne = 0;
        $this->_teamID = 0;
        $this->_totalUserID = 0;
        $this->_avgRating = 0;
        $this->_avgUser = 0;
    }
    
    public function __destruct()
    {
        unset($this->_avgRating, $this->_avgUser, $this->_matchID, $this->_playerID, $this->_playerImage, $this->_ratingUser, $this->_ratingVne, $this->_teamID, $this->_totalUserID);
    }
    
    /**
     * Initialize data
     * @param array $entity
     * @return Fpt_Business_RatingPlayerStatistic_Metadata_RatingPlayerStatistic 
     * @author QuangTM
     */
    public function init($entity)
    {
        $this->_matchID = intval($entity['match_id']);
        $this->_playerID = intval($entity['player_id']);
        $this->_playerImage = isset($entity['image']) ? $entity['image'] : NULL;
        $this->_ratingUser = intval($entity['rating_user']);
        $this->_ratingVne = !isset($entity['rating_vne']) ? 0 : intval($entity['rating_vne']);
        $this->_teamID = intval($entity['team_id']);
        $this->_totalUserID = intval($entity['total_userid']);
        $this->_avgRating = number_format(($this->_ratingUser + $this->_ratingVne) / ($this->_totalUserID + 1), 2);
        $this->_avgUser = number_format($this->_ratingUser / $this->_totalUserID, 2);
        return $this;
    }
    
    /**
     * Get formated data
     * @return array
     * @author QuangTM
     */
    public function getFormatedData()
    {
        return array(
            'MatchID'     => $this->_matchID,
            'TeamID'      => $this->_teamID,
            'PlayerID'    => $this->_playerID,
            'PlayerImage' => $this->_playerImage,
            'TotalUserID' => $this->_totalUserID,
            'RatingUser'  => $this->_ratingUser,
            'RatingVne'   => $this->_ratingVne,
            'AvgRating'   => $this->_avgRating,
            'AvgUser'     => $this->_avgUser,
        );
    }

}